The following example shows the use of BinaryReader.PeekChar method

C# .NET

 

Blaze++ .NET

static String DoTest()
{
         String fileName = "c:\\Test.dat";

         Single aspectRatio = 1.3333F;
         String lookupDir = "C:\\AppDirectory";
         Int32 autoSaveTime = 30;
         Boolean showStatusBar = false;
         String strOut = "";
         BinaryWriter binWriter(File::Open(fileName, FileMode::Create));
         try
         {
                  binWriter.Write(aspectRatio);
                  binWriter.Write(lookupDir);
                  binWriter.Write(autoSaveTime);
                  binWriter.Write(showStatusBar);
         }
         catch(Exception ex)
         {
                  strOut = ex.Message;
                  return strOut;
         }
         binWriter.Close();
         strOut = "File saved okay\r\n";

         BinaryReader binReader(File::Open(fileName, FileMode::Open));
         try
         {
                  if(binReader.PeekChar() != -1)
                  {

                           Single aspectRatioRet = binReader.ReadSingle();
                           String lookupDirRet = binReader.ReadString();
                           Int32 autoSaveTimeRet = binReader.ReadInt32();
                           Boolean showStatusBarRet = binReader.ReadBoolean();

                           strOut += (aspectRatioRet.ToString() + Environment::NewLine);
                           strOut += (lookupDirRet.ToString() + Environment::NewLine);
                           strOut += (autoSaveTimeRet.ToString() + Environment::NewLine);
                           strOut += (showStatusBarRet.ToString() + Environment::NewLine);
                           strOut += "File read okay\r\n";
                  }
         }
         catch(Exception ex)
         {
                  strOut = ex.Message;
                  return strOut;
         }
         binReader.Close();
         return strOut;
}